package io.gitee.yxsnake.embark.web.core.condition;

import org.dromara.hutool.core.text.StrUtil;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.lang.NonNull;

/**
 * @author snake
 * @description
 * @since 2024/9/29 0:54
 */
public class CustomCondition implements Condition {

    private final String key;
    private final String value;

    public CustomCondition(String key, String value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public boolean matches(@NonNull ConditionContext context,
                           @NonNull AnnotatedTypeMetadata metadata) {
        String beanName = context.getEnvironment().getProperty(key);
        return StrUtil.equalsIgnoreCase(beanName, value);
    }
}

